﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMCSerialTransfer
{
    public partial class frmMemory : Form
    {
        public int Address;
        public int Length;
        public bool isRam;
        public bool Receiving;
        public frmMemory()
        {
            InitializeComponent();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            string text;

            text = txtAddr.Text;

            try
            {
                if (text[0] == '$')
                {
                    text = text.Substring(1, text.Length - 1);
                    Address = Convert.ToInt32(text, 16);
                }
                else
                {
                    Address = Convert.ToInt32(text);
                }
                if (Receiving)
                {
                    text = txtLength.Text;
                    if (text[0] == '$')
                    {
                        text = text.Substring(1, text.Length - 1);
                        Length = Convert.ToInt32(text, 16);
                    }
                    else
                    {
                        Length = Convert.ToInt32(text);
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Address is not numeric", "Non numeric", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtAddr.Focus();
                return;
            }

            if (rmemory1.Checked)
                isRam = true;
            else
                isRam = false;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void frmMemory_Load(object sender, EventArgs e)
        {
         
            lblLength.Enabled = Receiving;
            txtLength.Enabled = Receiving;

        }

        

        
    }
}
